#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;

/*
 容器：顺序型和关联型
 顺序型容器中：
 vector和list的区别
 （1）vector内部是用动态数组实现的，内存连续，查找和修改比较快
 （2）list内部是用双向链表实现的，内存不连续，增加和删除比较快
 内联型容器中
 set和map的区别：
 （1）set内部是用红黑树实现的，里边的元素不能重复，且是有序的
 （2）map内部是用红黑树实现的，里边的元素是键值对（key->value),key不能重复，值可以


 栈stack和队列queue
 （1）动态数组实现的
 （2）stack先进后出，queue先进先出
 （3）

 */


void test01()
{
    string str1="hello";
    for (string::iterator it=str1.begin(); it!=str1.end();++it) {
        if(*it=='l')
            *it='*';
        cout<<*it<<" ";
    }
    cout<<endl;
    for(string::reverse_iterator it=str1.rbegin();it!=str1.rend();++it){
        cout<<*it<<" ";
    }
    cout<<endl;
    for(string:: const_iterator  it=str1.cbegin();it!=str1.cend();++it){
        cout<<*it<<" ";
    }
    cout<<endl;
    for(string:: const_reverse_iterator  it=str1.crbegin();it!=str1.crend();++it){
        cout<<*it<<" ";
    }
    cout<<endl;
}

void test02()
{
    string str="mayi";
    for(auto it =str.begin();it!=str.end();++it)
    {
        cout<<*it<<" ";
    }
    cout<<endl;

    // 范围遍历
    for(const char& ch:str){
        cout<<ch<<" ";
    }
    cout<<endl;

    for(char& ch:str){
        if(ch=='a') {
        ch='*';
        }
    }
    cout<<str<<endl;

    for(const auto& ch:str){
        cout<<ch<<" ";
    }
    cout<<endl;
}

void test03(){
    vector<int> arr={1,2,3,4,5};  //采用初始化列表的方式初始化vector
    vector<int> vec;
    vec.push_back(23);
    vec.push_back(24);
    vec.push_back(22);
    vec.push_back(21);

    for(int i=0;i<vec.size();++i)
    {
        cout<<vec[i]<<" ";
    }
    cout<<endl;

    for(vector<int>::iterator it=vec.begin();it!=vec.end();++it)
    {
        cout<<*it<<" ";
    }
    cout<<endl;

    for(auto it=vec.begin();it!=vec.end();++it)
    {
        cout<<*it<<" ";
    }
    cout<<endl;

    for(const int &val: vec){
        cout<<val<<" ";
    }
    cout<<endl;
}

typedef unsigned int UINT;
void test04()
{
    vector<char> arr ={'a','b','c'};
    vector<string> vec={"zhaosi","wangwu","zhangsan"};
    UINT cnt=0;
    for(auto &elem:vec){
        if(elem.size()>cnt)
        {
            cnt=elem.size();
        }
    }
    cout<<cnt<<endl;
}

void test05()
{
    string s1;
    string s2(s1);
    string str="hello world";
    string s3(str,1,4);  //下标1开始截取4个 strnpos//最后一个
    cout<<s3<<endl;
    string s4(str,3);  //下标3开始都截取
    cout<<s4<<endl;

    const char *p="hello world";
    string s5(p);
    cout<<s5<<endl;

    string s6(p,3);
    cout<<s6<<endl;

    string s7("mayi");
    string s8="mayi";

    string s9(str.begin(),str.end());
    cout<<s9<<endl;

    string s10(str.rbegin(),str.rend());
    cout<<s10<<endl;
}

void test06()
{
    string str="hello";
    reverse(str.begin(),str.end());
    cout<<str<<endl;
}

void test07()
{
    string str="zhaosi";
    string str2;
    str2=str;
    cout<<str2<<endl;

    cout<<str.length()<<endl;
    cout<<str.size()<<endl;
    string s;
    cout<<s.length()<<endl;
    cout<<s.size()<<endl;

    cout<<boolalpha<<str.empty()<<endl;

    str.clear();  //清空
    cout<<str.length()<<endl;
    cout<<"***"<<str<<"***"<<endl;

    cout<<str.max_size()<<endl;
}

int main()
{
    test07();
    //test06();
    // test05();
    // test04();
    // test02();
    // test03();
   // test01();
    return 0;
}